<!-- SimpleExample.jsp -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>懶人工作誌: PHPRPC in Java Annotation - 極限懶人包   - 範例</title>
<script src="../phprpc-all-compressed.js"></script>
<script src="../../js/google-code-prettify/prettify.js"></script>
<link href="../../js/google-code-prettify/prettify.css" type="text/css" rel="stylesheet" />
<script>
	var registerMethod = [ "get", "set", "getPrivate", "getFriendly", "getProtected" ];
	var phprpcHost = "";
	var contextPath = "<%=request.getContextPath()%>";
	var phprpcPath = "/PhprpcSimpleExample.phprpc";
	var client = new PHPRPC_Client(
					// server full path
					phprpcHost + contextPath + phprpcPath,
					// register method array
					registerMethod);
	// 顯示 server 回應內容
	var showResult = function(result) {
		alert(result);
	}

	function onGet() {
		client.get(showResult);
	}

	function onSet() {
		var msg = prompt("set parameter ", "Greeting");
		client.set(msg, showResult);
	}
	
	function phprpc( method ){
		client.invoke( method , showResult );
	}
</script>
</head>
<body onload="prettyPrint()">
<button onclick="onGet();">get</button>
<button onclick="onSet();">set</button>
<button onclick="phprpc('getPrivate');">getPrivate</button>
<button onclick="phprpc('getFriendly');">getFriendly</button>
<button onclick="phprpc('getProtected');">getProtected</button>
<pre class="prettyprint linenums lang-java">
@PHPRPC(urlPattern = "/PhprpcSimpleExample.phprpc")
public class PhprpcSimpleExample {

	public String get(){
		return "Hello";
	}
	
	public static String set(String msg){
		return msg;
	}
	
	/**
	 * Only public method publish 
	 * 
	 * example : try other access modifier
	 */
	
	private String getPrivate(){
		// client got NoSuchMethodException
		return "private got";
	}
	
	String getFriendly(){
		// client got NoSuchMethodException
		return "friendly get";
	}
	
	protected String getProtected(){
		// client got NoSuchMethodException
		return "protected got";
	}
	
}
</pre>
</body>
</html>